/**
 * 
 */
package edu.umd.clip.lm.model.training;

import edu.umd.clip.lm.model.training.NewTrainer.Distributions;

/**
 * @author Denis Filimonov <den@cs.umd.edu>
 *
 */
public abstract class AbstractQuestionEstimator {
	private static long totalCounts[];
	
	public static class Result {
		double cost;
		double trueCost;
		double falseCost;
		
		public Result(double cost) {
			this.cost = cost;
		}

		public double getCost() {
			return cost;
		}

		public double getTrueCost() {
			return trueCost;
		}

		public double getFalseCost() {
			return falseCost;
		}
		
		public void setupFalseActiveNode(int dataIdx, ActiveTreeNode activeNode, ActiveTreeNode parentNode, Distributions distributions) {
			activeNode.nodeCosts[dataIdx] = falseCost;
		}
		
		public void setupTrueActiveNode(int dataIdx, ActiveTreeNode activeNode, ActiveTreeNode parentNode, Distributions distributions) {
			activeNode.nodeCosts[dataIdx] = trueCost;
		}

		@Override
		public String toString() {
			return "Result [cost=" + cost + ", falseCost=" + falseCost
					+ ", trueCost=" + trueCost + "]";
		}
	}
	
	public abstract boolean prePruningRule(ActiveTreeNode activeNode);
	
	public abstract Result estimateQuestion(int data, ActiveTreeNode activeNode, NewTrainer.Distributions distributions);
	public abstract boolean isGood(int data, Result result, ActiveTreeNode activeNode);
	
	public boolean isGood(Result results[], ActiveTreeNode activeNode) {
		for(int i=0; i<results.length; ++i) {
			Result result = results[i];
			if (!isGood(i, result, activeNode)) return false;
		}
		return true;
	}

	public static long[] getTotalCounts() {
		return totalCounts;
	}

	public static void setTotalCounts(long[] totalCounts) {
		AbstractQuestionEstimator.totalCounts = totalCounts;
	}
	
}
